<!doctype html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>登录-信号集中监测系统登录</title>
	<meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <meta http-equiv="Cache-Control" content="no-siteapp" />
    <link rel="shortcut icon" href="./favicon.ico" type="image/x-icon" />
    <link rel="stylesheet" href="./static/css/font.css">
	<link rel="stylesheet" href="./static/css/weadmin.css">
    <script src="./layui/layui.js" charset="utf-8"></script>

</head>
<body class="login-bg">
    
    <div class="login">
        <div class="message">信号集中监测系统登录</div>
        <div id="darkbannerwrap"></div>
        
        <form method="post" class="layui-form" >
            <input name="username" placeholder="用户名"  type="text" lay-verify="required" class="layui-input" >
            <hr class="hr15">
            <input name="password" lay-verify="required" placeholder="密码"  type="password" class="layui-input">
            <hr class="hr15">
            <input class="loginin" value="登录" lay-submit lay-filter="login" style="width:100%;" type="submit">
            <hr class="hr20" >
        </form>
    </div>

    <script type="text/javascript">
            // var webSocket = null;
            // InitWebSocket();

        	layui.extend({
				admin: '{/}./static/js/admin'
			});
            layui.use(['form','layer'], function(){
              var form = layui.form
              $ = layui.jquery;            

              form.on('submit(login)', function(data){
                // var jo = {};

                // jo.Query = 'Login';
                // jo.Id = data.field.username;
                // jo.Password = data.field.password;
                // jo.Result = '';

                // var json = JSON.stringify(jo, null, 2);
                // webSocket.send(json);
                // $.ajax({
                //     type: "GET",
                //     url: "/v1/users/?query=Name%3A" + data.field.username + "%2CPassword%3A" + data.field.password,
                //     contentType: "application/json",
                //     accept: "application/json",
                //     // data: "?query=Name%3A" + data.field.username + "%2CPassword%3A" + data.field.password,
                //     success: function(res) {
                //         if (res.code == 0) {
                //             location.href='./index.html?user=' + res.data[0].Name;
                //         } else {
                //             layer.msg("用户名或密码错误！");
                //         }
                //     }
                // });

                $.ajax({
                    type: "GET",
                    url: "WebUserLogin.Lq",
                    contentType: "application/json",
                    accept: "application/json",
                    data: {UserName:data.field.username, Password:data.field.password},
                    success: function(res) {
                        var json = JSON.parse(res);
                        if (json[0].Result == 'Success') {
                            location.href='./index.html?user=' + json[0].UserName;
                        } else {
                            layer.msg("用户名或密码错误！");
                        }
                    },
                    error: function(XMLHttpRequest, textStatus, errorThrown) {
                        layer.msg(textStatus);
                    }
                });
                return false;
              });
            }); 

        function InitWebSocket(){
            var host = window.location.host;
            var port = window.location.port;
            if(port != ""){
                host = host + ":" + port;
            }                
            var url = 'ws://' + host + '/websocket/';

            webSocket = new WebSocket(url);	

            webSocket.binaryType = 'arraybuffer';

            webSocket.onopen = function(event){
                onOpen(event)
            };
    
            webSocket.onmessage = function(event){
                onMessage(event)
            };

            //定时发送心跳
            var time = window.setInterval(Heartbeat, 30000);
        }

        function onMessage(event){
            
        }
        
        function onOpen(event){
            
        }   
        //定时执行的任务
        function Heartbeat(){
            if(webSocket.readyState === webSocket.OPEN){               
                webSocket.send(new Blob(["Hearbeat"], { type: "" }));
            }
        }
    </script>  
    <!-- 底部结束 -->
</body>
</html>